package com.example.yls.demoa;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

public class ImageView_Activity extends AppCompatActivity implements View.OnClickListener {
        private Button pre;
        private Button next;
        private ImageView imageView;
        private int[] image={R.drawable.one,R.drawable.two,R.drawable.three,R.drawable.four,R.drawable.five};
        private int position=0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_image_view);
        pre=findViewById(R.id.pre);
        next=findViewById(R.id.next);
        pre.setOnClickListener(this) ;
        next.setOnClickListener(this) ;
        imageView=findViewById(R.id.imageView);


    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.pre:
                position--;
                if(position<0){

                    position=image.length-1;
                }
                imageView.setImageResource(image[position]);
                break;
            case R.id.next:
                position++;
                if(position>=image.length){
                    position=0;
                }
                imageView.setImageResource(image[position]);
                break;
        }
    }
}
